home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FPRINTF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  938 b   |  28 lines

  1. /* fprintf.c from p. 423 of Turbo C Bible */
  2. #include <stdio.h>
  3. char str[] = "Testing fprintf...";
  4. char c = '\n';
  5. int i = 100;
  6. double x = 1.23456;
  7. main()
  8. {
  9.     FILE *outfile;
  10.     char filename[81];
  11.     printf("Enter name of a file to open for WRITING:");
  12.     gets(filename);
  13.                 /*  Open the file for reading  */
  14.     if ((outfile = fopen(filename, "w")) == NULL)
  15.     {
  16.     printf("fopen failed.\n");
  17.     exit(0);
  18.     }
  19.                 /*  Write to this file ...  */
  20.     fprintf(outfile, "%s writing to file %s%c", str, filename, c);
  21.     fprintf(outfile, "Integer: decimal = %d, \ octal = %o, hex = %X\n",
  22.         i,i,i);
  23.     fprintf(outfile, "Double: %f(in default f format)\n", x);
  24.     fprintf(outfile, "        %.2f(in >2f format)\n", x);
  25.     fprintf(outfile, "        %g(in default g format)\n", x);
  26.                 /*  Tell user to type file to see results  */
  27.     fprintf(stdout, "Use the command 'TYPE %s' to see results\n", filename);
  28. }